package com.web.service.impl;

import com.dto.BaseDto;
import com.dto.MessageEnum;
import com.entity.Platformactivityrecod;
import com.page.PageInfo;
import com.web.dao.PlatformactivityrecodDao;
import com.web.service.PlatformactivityrecodService;
import com.web.service.PlatformactivityrecodServiceForFestivalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service
public class PlatformactivityrecodServiceImpl implements PlatformactivityrecodService {
    @Resource
    PlatformactivityrecodDao platformactivityrecodDao;
    @Resource
    PlatformactivityrecodServiceForFestivalService platformactivityrecodServiceForFestivalService;

    public BaseDto<Platformactivityrecod> getAll() throws Exception {
        List<Platformactivityrecod> platformactivityrecods = platformactivityrecodDao.getAll();
        MessageEnum messageEnum = platformactivityrecods.size() > 0? MessageEnum.GETALLSTUDENTSUCCESS: MessageEnum.GETALLSTUDENTNODATA;
        BaseDto<Platformactivityrecod> dto = new BaseDto(messageEnum,platformactivityrecods);

        return dto;
    }

    public BaseDto<Platformactivityrecod> selectByPrimaryKey(int parid) throws Exception {
        Platformactivityrecod platformactivityrecod = platformactivityrecodDao.selectByPrimaryKey(parid);
        MessageEnum messageEnum = Optional.ofNullable(platformactivityrecod).isPresent()? MessageEnum.GETALLSTUDENTSUCCESS:MessageEnum.GETALLSTUDENTNODATA;
        BaseDto<Platformactivityrecod> dto = new BaseDto(messageEnum,platformactivityrecod);

        return dto;
    }
    
    public BaseDto<Platformactivityrecod> getPlatformactivityrecodsByPage(PageInfo pageInfo) throws Exception {
        List<Platformactivityrecod> platformactivityrecods = platformactivityrecodDao.getPlatformactivityrecodsByPage(pageInfo);
        MessageEnum messageEnum = platformactivityrecods.size() > 0? MessageEnum.GETBYPAGESUCCESS: MessageEnum.GETBYPAGEFAIL;
        BaseDto<Platformactivityrecod> dto = new BaseDto(messageEnum,platformactivityrecods);

        return dto;
    }

    public BaseDto<Platformactivityrecod> add(Platformactivityrecod platformactivityrecod) throws Exception {
        int result = platformactivityrecodDao.add(platformactivityrecod);
        MessageEnum messageEnum = result > 0? MessageEnum.ADDFESTIVALSUCCESS: MessageEnum.ADDFESTIVALFAIL;
        BaseDto<Platformactivityrecod> dto = new BaseDto(messageEnum,result);

        return dto;
    }
    
    public BaseDto<Platformactivityrecod> update(int parid) throws Exception {
        Platformactivityrecod platformactivityrecod = platformactivityrecodDao.selectByPrimaryKey(parid);
        int result = platformactivityrecodDao.update(platformactivityrecod);
        MessageEnum messageEnum = result > 0? MessageEnum.UPDATESUCCESS: MessageEnum.UPDATEFAIL;
        BaseDto<Platformactivityrecod> dto = new BaseDto(messageEnum,result);

        return dto;
    }

    public BaseDto<Platformactivityrecod> addByFestival(Platformactivityrecod platformactivityrecod) throws Exception {
        int result = platformactivityrecodDao.add(platformactivityrecod);
        platformactivityrecodServiceForFestivalService.ExistFestival(platformactivityrecod.getFid());
        MessageEnum messageEnum = result > 0? MessageEnum.ADDFESTIVALSUCCESS: MessageEnum.ADDFESTIVALFAIL;
        BaseDto<Platformactivityrecod> dto = new BaseDto(messageEnum,result);

        return dto;
    }


}
